package com.qkbb.admin.kuibu.qkbb.activity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.Button;

import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest;
import com.qkbb.admin.kuibu.R;
import com.qkbb.admin.kuibu.qkbb.funcation.SDCardHelper;
import com.qkbb.admin.kuibu.qkbb.url.Url;

public class Route_details extends AppCompatActivity {
    private Button joinbutton;
    private Button lookbutton;
    private int roadid;
    private String roadname;
    private String user_token;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.route_details);
        user_token= SDCardHelper.loadFileFromSdCard("user_token",getApplicationContext());
        Log.e("join",user_token);
        Intent intent=getIntent();
        roadid=intent.getIntExtra("roadid",103);
        roadname=intent.getStringExtra("roadname");
//        roadid=intent.getIntExtra("roadid", 101);
        Log.e("roadid", roadid + "");
        joinbutton= (Button) findViewById(R.id.route_details_button);
        lookbutton= (Button) findViewById(R.id.route_details_look);
        lookbutton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent1=new Intent(Route_details.this,LookThisWay.class);
                intent1.putExtra("roadid",roadid);
                intent1.putExtra("roadname",roadname);
                startActivity(intent1);
            }
        });
        joinbutton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                RequestParams params=new RequestParams();
                params.addBodyParameter("roadid",roadid+"");
                HttpUtils utils=new HttpUtils();
                Log.e("join",Url.JOINGAME + user_token);
                utils.send(HttpRequest.HttpMethod.PUT, Url.JOINGAME + user_token, params, new RequestCallBack<String>() {
                    @Override
                    public void onSuccess(ResponseInfo<String> responseInfo) {
                        String str=responseInfo.result;
                        Log.e("back", str);

                    }

                    @Override
                    public void onFailure(HttpException e, String s) {
                        Log.e("onFailure",s);
                    }
                });

            }
        });

    }
}
